<?php
/**
 * controller file Created by PhpStorm.
 * User: wumengmeng
 * Date: 2019/09/02
 * Time: 01:52
 */

namespace Modules\Admin\Http\Controllers;

use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Request;
use Modules\Admin\Service\GoodsSpecsCateService;

class GoodsSpecsCateController extends BaseController
{


    /**
     * 商品规格属性 列表
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function index()
    {
        $search = Request::input();
        $res = GoodsSpecsCateService::get_list($search);

        echo_error($res);
        return view('admin::goodsSpecsCate.index', ['arr_data' => $res['data']]);
    }

    /**
     * 添加 商品规格属性 页面
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function create()
    {
        return view('admin::goodsSpecsCate.create');
    }

    /**
     * 添加 商品规格属性 操作
     *
     * @return mixed
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function store()
    {
        $arr_input = Request::input();

        return GoodsSpecsCateService::add_one($arr_input);
    }

    /**
     * 修改 商品规格属性 页面
     *
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function edit()
    {
        $nId = Request::get('id', 0);
        $res = GoodsSpecsCateService::get_one((int)$nId);
        echo_error($res);

        $arr_data = [
            'arr_data' => $res['data'],
        ];
        return view('admin::goodsSpecsCate.edit', $arr_data);
    }

    /**
     * 修改 商品规格属性 页面操作
     *
     *
     * @return array|\Illuminate\Http\RedirectResponse
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function update()
    {
        $arr_input = Request::input();

        return GoodsSpecsCateService::edit_one($arr_input);
    }


    /**
     * 更改 XXX 状态
     *
     * @return array|\Illuminate\Http\RedirectResponse
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function change_state()
    {
        $arr_input = Request::input();
        return GoodsSpecsCateService::change_one_state($arr_input);
    }

    /**
     * 删除 商品规格属性
     *
     * @return array|\Illuminate\Http\RedirectResponse
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function del()
    {
        $n_id = (int)Request::get('id', 0);

        return GoodsSpecsCateService::delete_one($n_id);
    }
}